package edu.sctu.practice.class02.yangyiqing.assign2;
import java.util.Scanner;

/**
 * Created by Administrator on 2015/10/8 0008.
 */
public class Rational {
    //（1）首先创建有理数类Rational，该类包含构造方法和加、减、乘、除方法。
    //（2）程序主方法中创建两个有理数对象，分别进行加、减、乘、除运算，并输出运算结果。


    public int num1;
    public int num2;
    int addResult;
    int reduceResult;
    int timesResult;
    int divideResult;


    public Rational(int num1, int num2) {
        this.num1 = num1;
        this.num2 = num2;
    }

    public int add() {
        addResult = num1 + num2;
        return addResult;
    }

    public int reduce() {
        reduceResult = num1 - num2;
        return reduceResult;
    }

    public int times() {
        timesResult = num1 * num2;
        return timesResult;
    }

    public int divide() {
        divideResult = num1 / num2;
        return divideResult;
    }

    public static void printResult(Rational r){
        System.out.println(r.num1+"+"+r.num2+"="+r.add());
        System.out.println(r.num1+"-"+r.num2+"="+r.reduce());
        System.out.println(r.num1+"*"+r.num2+"="+r.times());
        System.out.println(r.num1+"/"+r.num2+"="+r.divide());
    }
    public static void getResult(){
        System.out.println("请输入两个数：（请注意，前一个数务必大于后一个数）");
        Scanner scanner= new Scanner(System.in);
        int number1=scanner.nextInt();
        int number2=scanner.nextInt();
        Rational rational = new Rational(number1, number2);
        rational.printResult(rational);
    }


}
